
package CCT220_Trabalho04_13106.view;


import java.util.LinkedList;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;


/**
 * </br>******************************
 * </br>Project: CCT220
 * </br>Package: CCT220_Trabalho04_13106.view
 * </br>Class: LimiteDisciplina
 * </br>Last Change: 08/10/2011 11:24:18 by marcel
 * </br>Description: Class the manage the limit between the Disciplina entity
 * and the user
 * </br>******************************</br>
 * 
 * @author marcel
 * @author 13106
 * 
 */
public class LimiteDisciplina {

	/**
	 * </br>******************************
	 * </br>Package: CCT220_Trabalho04_13106.view
	 * </br>Class: LimiteDisciplina
	 * </br>Method: montaMenu
	 * </br>Last Change: 08/10/2011 11:24:20 by marcel
	 * </br>Description: Method that show the options to the user and return the
	 * chosen one
	 * </br>******************************</br>
	 * 
	 * @return the chosen option
	 */
	public int montaMenu() {

		int escolha = -1;
		String escolhaInformada = "";
		do {

			escolhaInformada = JOptionPane
			        .showInputDialog("Escolha uma opção do menu principal>disciplina:\n"
			                + "[1] Adicionar disciplina\n"
			                + "[2] Listar uma disciplina\n"
			                + "[3] Listar todas disciplinas\n"
			                + "[4] Remover disciplina\n"
			                + "[5] Voltar & salvar");
			try {
				escolha = Integer.parseInt(escolhaInformada);
				if ((escolha < 1) || (escolha > 5)) {
					JOptionPane.showMessageDialog(null,
					        "Use apenas números entre 1 e 5!!!", "Erro",
					        JOptionPane.ERROR_MESSAGE);
				}
			} catch (NumberFormatException nExc) {
				JOptionPane.showMessageDialog(null, "Use apenas números!!!",
				        "Erro", JOptionPane.ERROR_MESSAGE);
			}

		} while ((escolha < 1) || (escolha > 5));
		return escolha;

	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Trabalho04_13106.view
	 * </br>Class: LimiteDisciplina
	 * </br>Method: capturaDadosCadastrais
	 * </br>Last Change: 08/10/2011 11:24:23 by marcel
	 * </br>Description: Method that capture the data for the new entity of
	 * Disciplina
	 * </br>******************************</br>
	 * 
	 * @return String[]
	 */
	public String[] capturaDadosCadastrais() {

		String dados[] = new String[2];
		dados[0] = JOptionPane.showInputDialog("Digite o codigo da disciplina");
		dados[1] = JOptionPane.showInputDialog("Digite o nome da disciplina");
		return dados;
	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Trabalho04_13106.view
	 * </br>Class: LimiteDisciplina
	 * </br>Method: selectOne
	 * </br>Last Change: 08/10/2011 11:24:25 by marcel
	 * </br>Description: Method that select one Disciplina from the given list
	 * and return its code
	 * </br>******************************</br>
	 * 
	 * @param list
	 * @return the code of the selected Disciplina
	 */
	public int selectOne(LinkedList<String> list) {

		JTextArea jta = new JTextArea();
		jta.setBackground(new JLabel().getBackground());
		jta.setForeground(new JLabel().getForeground());
		jta.setEditable(false);
		jta.setText("Digite o codigo de um dos itens abaixo:\n\n" + list);
		int code = -1;
		code = Integer.parseInt(JOptionPane.showInputDialog(null, jta,
		        "Selecao de Disciplina", JOptionPane.INFORMATION_MESSAGE));
		return code;
	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Trabalho04_13106.view
	 * </br>Class: LimiteDisciplina
	 * </br>Method: show
	 * </br>Last Change: 08/10/2011 11:24:26 by marcel
	 * </br>Description: Method that show the given String in a JOptionPane
	 * </br>******************************</br>
	 * 
	 * @param string
	 */
	public void show(String string) {

		JTextArea jta = new JTextArea();
		jta.setBackground(new JLabel().getBackground());
		jta.setForeground(new JLabel().getForeground());
		jta.setEditable(false);
		jta.setText(string);
		JOptionPane.showMessageDialog(null, jta, "Disciplina",
		        JOptionPane.INFORMATION_MESSAGE);
	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Trabalho04_13106.view
	 * </br>Class: LimiteDisciplina
	 * </br>Method: showAll
	 * </br>Last Change: 08/10/2011 11:24:28 by marcel
	 * </br>Description: Method that show the given LinkedList<String> in a
	 * JOptionPane
	 * </br>******************************</br>
	 * 
	 * @param lista
	 */
	public void showAll(LinkedList<String> lista) {

		JTextArea jta = new JTextArea();
		jta.setBackground(new JLabel().getBackground());
		jta.setForeground(new JLabel().getForeground());
		jta.setEditable(false);
		jta.setText("Lista de Disciplinas: \n\n" + lista);
		JOptionPane.showMessageDialog(null, jta, "Lista Disciplinas",
		        JOptionPane.INFORMATION_MESSAGE);

	}

}
